import 'package:flutter/material.dart';
import 'package:untitled/utils/SnackBarHepler.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      scaffoldMessengerKey: ScaffoldMessengerGlobalKey,
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage>
    with SingleTickerProviderStateMixin {
  @override
  Widget build(BuildContext context) {
    //脚手架
    return Builder(
      builder: (BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('弹框'),
            backgroundColor: Colors.blue,
            foregroundColor: Colors.white,
          ),

          body: SizedBox.expand(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                ElevatedButton(
                  onPressed: () {
                    test();
                  },
                  child: Text("显示弹框1"),
                ),
              ],
            ),
          ),
        );
      },
    );
  }

  void test() {
    showDialog(
      context: context,
      //遮罩层的颜色
      barrierColor: Colors.black54,
      //点击遮罩是否可关闭 true 关闭
      barrierDismissible: true,
      //安全区域
      useSafeArea: true,
      builder: (BuildContext context) {
        return AlertDialog(
          //背景颜色
          backgroundColor: Colors.white,
          //阴影的高度
          elevation: 20,
          //阴影 的颜色
          shadowColor: Colors.red.withValues(alpha: 0.5),
          surfaceTintColor: Colors.blue,
          //形状配置
          shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
          //对话框在屏幕中的对齐方式
          alignment: Alignment(0, 0),
          //尺寸约束
          constraints: BoxConstraints(
            minWidth: 300,
            maxWidth: 500,
            minHeight: 200,
            maxHeight: 400,
          ),
          //内容滑动
          scrollable: true,
          //图标
          icon: Icon(Icons.warning),
          //图标的内边距
          iconPadding: EdgeInsets.all(20),
          //图标的颜色
          iconColor: Colors.red,
          //标题的内边距
          titlePadding: EdgeInsets.all(20),
          titleTextStyle: TextStyle(
            fontSize: 18,
            fontWeight: FontWeight.bold,
            color: Colors.black,
          ),

          //标题
          title: Text('标题'),
          //中间的内容
          content: Container(
            child: Column(
              children: [
                Text('这里是内容 '),
                Text('这里是内容 '),
                SizedBox(height: 400),
                SizedBox(height: 400),
              ],
            ),
          ),
          //中间内容 的内边距
          contentPadding: EdgeInsets.all(20),
          contentTextStyle: TextStyle(fontSize: 14, color: Colors.grey[600]),
          actionsPadding: EdgeInsets.all(20),
          //底部按钮的对齐方式
          actionsAlignment: MainAxisAlignment.spaceEvenly,
          //水平展示不下时 垂直方向展示对齐 方式
          actionsOverflowAlignment: OverflowBarAlignment.end,
          //底部的按钮 非常多的时候
          actionsOverflowDirection: VerticalDirection.down,
          //按钮之间的间距
          actionsOverflowButtonSpacing: 20,
          //底部的按钮
          actions: [
            TextButton(
              onPressed: () {
                Navigator.of(context).pop();
              },
              child: Text('取消'),
            ),
            TextButton(onPressed: () {}, child: Text('确定')),
          ],
        );
      },
    );
  }
}
